import request from '@/utils/request'

/**
 * 订单数据统计排行
 * 包含初始化及查询
 * @export
 * @param {any} id 查询用户的id
 * @param {any} max 最高
 * @param {any} min 最低
 * @param {any} twenty 最近20
 * @param {any} thirty 最近30
 * @param {any} sixty 最近60
 * @returns JSON
 */
export function sortInit(id, max, twenty) {
  return request({
    url: '/rankorder',
    method: 'GET',
    params: { id, max, twenty }
  })
}

export function sortMax20(id, max, twenty) {
  return request({
    url: '/rankorder',
    method: 'GET',
    params: { id, max, twenty }
  })
}

export function sortMax30(id, max, thirty) {
  return request({
    url: '/rankorder',
    method: 'GET',
    params: { id, max, thirty }
  })
}

export function sortMax60(id, max, sixty) {
  return request({
    url: '/rankorder',
    method: 'GET',
    params: { id, max, sixty }
  })
}

export function sortMin20(id, min, twenty) {
  return request({
    url: '/rankorder',
    method: 'GET',
    params: { id, min, twenty }
  })
}

export function sortMin30(id, min, thirty) {
  return request({
    url: '/rankorder',
    method: 'GET',
    params: { id, min, thirty }
  })
}

export function sortMin60(id, min, sixty) {
  return request({
    url: '/rankorder',
    method: 'GET',
    params: { id, min, sixty }
  })
}

/**
 * 订单数据明细
 * 包含初始化及查询实例
 * @param {Number} id 代理商id
 */
export function listInit(id, page) {
  return request({
    url: '/order',
    method: 'GET',
    params: { id, page }
  })
}

/**
 * 订单列表查询
 * @param {Number} id 代理商id
 * @param {*} date 查询参数
 */
export function listSearch(id, date) {
  return request({
    url: '/order',
    method: 'GET',
    params: { id,
      min: date.min,
      max: date.max,
      start_time: date.time ? date.time[0] : '',
      end_time: date.time ? date.time[1] : '',
      pay_status: date.pay_status,
      store_id: date.store_name,
      merchant_name: date.name,
      merchant_type: date.merchant_type,
      channel: date.channel,
      c_channel: date.c_channel,
      ordernumber: date.ordernumber,
      agent_id: date.agent_name,
      pay_resource: date.pay_resource
    }
  })
}

/**
 * 查询昨日订单
 * @param {Number} id 代理商id
 * @param {String} data 搜索参数集合
 * @param {Boolean} beforeorder 昨日标识
 */
export function listYesterDay(id, data) {
  return request({
    url: '/order',
    method: 'GET',
    params: { id,
      min: data.min,
      max: data.max,
      start_time: data.time ? data.time[0] : '',
      end_time: data.time ? data.time[1] : '',
      pay_status: data.pay_status,
      store_id: data.store_name,
      merchant_name: data.name,
      merchant_type: data.merchant_type,
      channel: data.channel,
      c_channel: data.c_channel,
      agent_id: data.agent_name,
      ordernumber: data.ordernumber,
      pay_resource: data.pay_resource,
      beforeorder: true
    }
  })
}

/**
 * 查询当日订单
 * @param {Number} id 代理商id
 * @param {String} data 搜索参数集合
 * @param {Boolean} today 当日标识
 */
export function listToDay(id, data) {
  return request({
    url: '/order',
    method: 'GET',
    params: { id,
      min: data.min,
      max: data.max,
      start_time: data.time ? data.time[0] : '',
      end_time: data.time ? data.time[1] : '',
      pay_status: data.pay_status,
      store_id: data.store_name,
      merchant_name: data.name,
      merchant_type: data.merchant_type,
      channel: data.channel,
      c_channel: data.c_channel,
      ordernumber: data.ordernumber,
      agent_id: data.agent_name,
      pay_resource: data.pay_resource,
      today: true
    }
  })
}

/**
 * 查询当月订单
 * @param {Number} id 代理商id
 * @param {String} data 搜索参数集合
 * @param {Boolean} themonth 当月标识
 */
export function listToMonth(id, data) {
  return request({
    url: '/order',
    method: 'GET',
    params: { id,
      min: data.min,
      max: data.max,
      start_time: data.time ? data.time[0] : '',
      end_time: data.time ? data.time[1] : '',
      pay_status: data.pay_status,
      store_id: data.store_name,
      merchant_name: data.name,
      merchant_type: data.merchant_type,
      channel: data.channel,
      c_channel: data.c_channel,
      ordernumber: data.ordernumber,
      agent_id: data.agent_name,
      pay_resource: data.pay_resource,
      themonth: true
    }
  })
}

/**
 * 查询分页数据
 * @param {Number} id 代理商id
 * @param {String} data 搜索参数集合
 * @param {Number} page 分页页码
 * @param {Number} state 状态
 */
export function listPage(id, data, page) {
  return request({
    url: '/order',
    method: 'GET',
    params: { id,
      min: data.min,
      max: data.max,
      start_time: data.time ? data.time[0] : '',
      end_time: data.time ? data.time[1] : '',
      pay_status: data.pay_status,
      store_id: data.store_name,
      merchant_name: data.name,
      merchant_type: data.merchant_type,
      channel: data.channel,
      c_channel: data.c_channel,
      ordernumber: data.ordernumber,
      pay_resource: data.pay_resource,
      page,
      agent_id: data.agent_name
    }
  })
}

/**
 * 蓝海订单
 * @param {Number} id 代理商编号
 * @param {Object} data 参数集
 */
export function listBule(id, data) {
  return request({
    url: '/order',
    method: 'GET',
    params: { id,
      min: data.min,
      max: data.max,
      start_time: data.time ? data.time[0] : '',
      end_time: data.time ? data.time[1] : '',
      pay_status: data.pay_status,
      store_id: data.store_name,
      merchant_name: data.name,
      merchant_type: data.merchant_type,
      channel: data.channel,
      c_channel: data.c_channel,
      ordernumber: data.ordernumber,
      agent_id: data.agent_name,
      pay_resource: data.pay_resource,
      blue: true
    }
  })
}

/**
 * 公益订单
 */
export function listCharity(id, data, page) {
  return request({
    url: '/order',
    method: 'GET',
    params: { id,
      min: data.min,
      max: data.max,
      start_time: data.time ? data.time[0] : '',
      end_time: data.time ? data.time[1] : '',
      pay_status: data.pay_status,
      store_id: data.store_name,
      merchant_name: data.name,
      merchant_type: data.merchant_type,
      channel: data.channel,
      c_channel: data.c_channel,
      ordernumber: data.ordernumber,
      agent_id: data.agent_name,
      pay_resource: data.pay_resource,
      page,
      charity: true
    }
  })
}

/**
 * 绿洲订单
 */
export function listGreen(id, data) {
  return request({
    url: '/order',
    method: 'GET',
    params: { id,
      min: data.min,
      max: data.max,
      start_time: data.time ? data.time[0] : '',
      end_time: data.time ? data.time[1] : '',
      pay_status: data.pay_status,
      store_id: data.store_name,
      merchant_name: data.name,
      merchant_type: data.merchant_type,
      channel: data.channel,
      c_channel: data.c_channel,
      ordernumber: data.ordernumber,
      agent_id: data.agent_name,
      pay_resource: data.pay_resource,
      green: true
    }
  })
}

/**
 * 蓝海订单分页
 * @param {Number} id 代理商编号
 * @param {Object} data 参数集
 */
export function listBulePage(id, data, page) {
  return request({
    url: '/order',
    method: 'GET',
    params: { id,
      page,
      min: data.min,
      max: data.max,
      start_time: data.time ? data.time[0] : '',
      end_time: data.time ? data.time[1] : '',
      pay_status: data.pay_status,
      store_id: data.store_name,
      merchant_name: data.name,
      merchant_type: data.merchant_type,
      channel: data.channel,
      c_channel: data.c_channel,
      ordernumber: data.ordernumber,
      agent_id: data.agent_name,
      pay_resource: data.pay_resource,
      blue: true
    }
  })
}

/**
 * 公益订单分页
 * @param {Number} id 代理商编号
 * @param {Object} data 参数集
 */
export function listCharityPage(id, data, page) {
  return request({
    url: '/order',
    method: 'GET',
    params: { id,
      page,
      min: data.min,
      max: data.max,
      start_time: data.time ? data.time[0] : '',
      end_time: data.time ? data.time[1] : '',
      pay_status: data.pay_status,
      store_id: data.store_name,
      merchant_name: data.name,
      merchant_type: data.merchant_type,
      channel: data.channel,
      c_channel: data.c_channel,
      ordernumber: data.ordernumber,
      agent_id: data.agent_name,
      pay_resource: data.pay_resource,
      blue: true
    }
  })
}

/**
 * 绿洲订单分页
 */
export function listGreenPage(id, data, page) {
  return request({
    url: '/order',
    method: 'GET',
    params: { id,
      page,
      min: data.min,
      max: data.max,
      start_time: data.time ? data.time[0] : '',
      end_time: data.time ? data.time[1] : '',
      pay_status: data.pay_status,
      store_id: data.store_name,
      merchant_name: data.name,
      merchant_type: data.merchant_type,
      channel: data.channel,
      c_channel: data.c_channel,
      ordernumber: data.ordernumber,
      agent_id: data.agent_name,
      pay_resource: data.pay_resource,
      green: true
    }
  })
}

/**
 * 今日订单查询分页数据
 * @param {Number} id 代理商id
 * @param {String} data 搜索参数集合
 * @param {Number} page 分页页码
 * @param {Number} state 状态
 */
export function listTodayPage(id, data, page) {
  return request({
    url: '/order',
    method: 'GET',
    params: { id,
      min: data.min,
      max: data.max,
      start_time: data.time ? data.time[0] : '',
      end_time: data.time ? data.time[1] : '',
      pay_status: data.pay_status,
      store_id: data.store_name,
      merchant_name: data.name,
      merchant_type: data.merchant_type,
      channel: data.channel,
      c_channel: data.c_channel,
      ordernumber: data.ordernumber,
      agent_id: data.agent_name,
      pay_resource: data.pay_resource,
      page,
      today: true
    }
  })
}

/**
 * 昨日订单查询分页数据
 * @param {Number} id 代理商id
 * @param {String} data 搜索参数集合
 * @param {Number} page 分页页码
 * @param {Number} state 状态
 */
export function listbeforeorderPage(id, data, page) {
  return request({
    url: '/order',
    method: 'GET',
    params: { id,
      min: data.min,
      max: data.max,
      start_time: data.time ? data.time[0] : '',
      end_time: data.time ? data.time[1] : '',
      pay_status: data.pay_status,
      store_id: data.store_name,
      merchant_name: data.name,
      merchant_type: data.merchant_type,
      channel: data.channel,
      agent_id: data.agent_name,
      c_channel: data.c_channel,
      ordernumber: data.ordernumber,
      pay_resource: data.pay_resource,
      page,
      beforeorder: true
    }
  })
}

/**
 * 当月订单查询分页数据
 * @param {Number} id 代理商id
 * @param {String} data 搜索参数集合
 * @param {Number} page 分页页码
 * @param {Number} state 状态
 */
export function listThemonthPage(id, data, page) {
  return request({
    url: '/order',
    method: 'GET',
    params: { id,
      min: data.min,
      max: data.max,
      start_time: data.time ? data.time[0] : '',
      end_time: data.time ? data.time[1] : '',
      pay_status: data.pay_status,
      store_id: data.store_name,
      merchant_name: data.name,
      merchant_type: data.merchant_type,
      channel: data.channel,
      c_channel: data.c_channel,
      agent_id: data.agent_name,
      ordernumber: data.ordernumber,
      pay_resource: data.pay_resource,
      page,
      themonth: true
    }
  })
}

/**
 * 订单模态框数据获取
 * @param {Number} id 查询订单id
 */
export function handleGetList(id) {
  return request({
    url: '/orderselect',
    method: 'GET',
    params: { id }
  })
}

/**
 * 获取下拉代理商数据
 * @param {Number} id 代理商id
 */
export function handelAgentName(id) {
  return request({
    url: '/getDetailed',
    method: 'GET',
    params: { id, requesttype: 1 }
  })
}

/**
 * 获取商户
 * @param {Number} id 代理商id
 * @param {*} mercategory 是否直属商户/全部商户
 */
export function handleShopName(id, mercategory, type) {
  if (type === 1) {
    return request({
      url: '/getDetailed',
      method: 'GET',
      params: { user_id: id, requesttype: 2, mercategory }
    })
  } else {
    return request({
      url: '/getDetailed',
      method: 'GET',
      params: { agent_num: id, requesttype: 2, mercategory }
    })
  }
}

/**
 * 获取门店名称
 * @param {Number} mer_id 商户id
 */
export function handleStoreName(mer_id) {
  return request({
    url: '/getDetailed',
    method: 'GET',
    params: { mer_id, requesttype: 3 }
  })
}

/**
 * 全部导出
 * @param {Number} value 日期
 * @param {Number} data 查询参数
 */
export function oderDownloadAll(value, data) {
  return request({
    url: '/order_export',
    method: 'GET',
    params: {
      export_day: value, min: data.min,
      max: data.max,
      start_time: data.time > 0 ? data.time[0] : '',
      end_time: data.time > 0 ? data.time[1] : '',
      pay_status: data.pay_status,
      store_id: data.store_name,
      merchant_name: data.name,
      merchant_type: data.merchant_type,
      channel: data.channel,
      c_channel: data.c_channel,
      agent_id: data.agent_name,
      ordernumber: data.ordernumber,
      pay_resource: data.pay_resource
    }
  })
}

/**
 * 网商大款失败初始化
 */
export function orderErrorInit() {
  return request({
    url: '/remittanceFail',
    method: 'GET'
  })
}

/**
 * 网上打款失败订单详情获取
 * @param {Number} batch_id 失败id
 */
export function orderListInit(batch_id) {
  return request({
    url: '/remittanceFailList',
    method: 'GET',
    params: { batch_id }
  })
}

/**
 * 网上打款失败订单详情分页
 * @param {Number} page 分页页码
 */
export function orderListPage(page, batch_id) {
  return request({
    url: '/remittanceFailList',
    method: 'GET',
    params: { page, batch_id }
  })
}

/**
 * 网上打款失败订单详情查看
 * @param {Number} id 订单id
 */
export function orderListItem(id) {
  return request({
    url: '/remittanceFailQuery',
    method: 'GET',
    params: { id }
  })
}

/**
 * 网上打款失败分组分页
 * @param {Number} page 分页页码
 */
export function orderGroupPage(page) {
  return request({
    url: '/remittanceFail',
    method: 'GET',
    params: { page }
  })
}

/**
 * 网商打款失败查询
 * @param {Object} date 查询参数
 */
export function orderGroupSearch(date) {
  return request({
    url: '/remittanceFail',
    method: 'GET',
    params: { batch_time: date.time }
  })
}

/**
 * 网商打款失败订单查询
 * @param {Object} date 查询订单号
 */
export function orderListSearch(date) {
  return request({
    url: '/remittanceFailList',
    method: 'GET',
    params: { order_no: date.order_num, batch_id: date.id }
  })
}
